package pacBioSimple;

public class PacBioBlastHitObject {

private	int begin_q = -1;
private	int begin_d = -1;
private	int end_q = -1;
private	int end_d = -1;
private String name ="";
private int alignmentLength =-1;
private double quality = 0.0;
private boolean type=false;
private int linker_distance = 49;
public PacBioBlastHitObject() {
}


public PacBioBlastHitObject(String[]blastResult)
{
	name = blastResult[0];
	alignmentLength = Integer.valueOf(blastResult[3]);
	begin_q = Integer.valueOf(blastResult[6]);
	end_q = Integer.valueOf(blastResult[7]);
	begin_d = Integer.valueOf(blastResult[8]);
	end_d= Integer.valueOf(blastResult[9]);
	quality = Double.valueOf(blastResult[2]);
	
	if(blastResult[1].equals("primer"))
	{
		type=true;
	}
}



public static boolean isIntersect(PacBioBlastHitObject a, PacBioBlastHitObject b)
{
	if(a.name.equals(b.name))
	{
		if(a.begin_q == b.begin_q || a.end_q == b.end_q || a.begin_q < b.end_q && b.end_q <= a.end_q || b.begin_q <= a.end_q && a.end_q <= b.end_q)
		{
			return true;
		}
		else
		{
			return false;
		}
	}
	return false;
}


public static PacBioBlastHitObject mergeObject(PacBioBlastHitObject a, PacBioBlastHitObject b)
{
	a.begin_q = Math.min(a.begin_q, b.begin_q);
	a.end_q = Math.max(a.end_q, b.end_q);
	
	if(!a.type && !b.type)
	{
		if(a.getBegin_d() > a.getEnd_d() && b.getBegin_d() > b.getEnd_d())
		{	//arg I have to use here the distanc
			a.begin_d = Math.max(Math.abs(a.begin_d-a.linker_distance),Math.abs(b.begin_d-b.linker_distance));
			a.end_d = Math.max(a.end_d, b.end_d);
		}
		else if(a.getBegin_d() > a.getEnd_d() && b.getBegin_d() < b.getEnd_d())
		{
			a.begin_d = Math.max(Math.abs(a.begin_d-a.linker_distance), b.begin_d);
			a.end_d = Math.max(b.end_d, Math.abs(a.end_d-b.linker_distance));
		}
		else if(a.getBegin_d() < a.getEnd_d() && b.getBegin_d() > b.getEnd_d())
		{
			a.begin_d = Math.max(Math.abs(b.begin_d-b.linker_distance), a.begin_d);
			a.end_d = Math.max(a.end_d, Math.abs(b.end_d-a.linker_distance));
		}
		else if(a.getBegin_d() < a.getEnd_d() && b.getBegin_d() < b.getEnd_d())
		{
			a.begin_d = Math.max(a.begin_d, b.begin_d);
			a.end_d = Math.max(Math.abs(a.end_d-a.linker_distance), Math.abs(b.end_d-b.linker_distance));
		}		
	}
	else
	{
		if(!b.type)
		{
			a.begin_d = b.getBegin_d();
			a.end_d = b.getEnd_d();
			a.type=false;
		}
	}
	return a;
}







	
public String getName() {
	return name;
}


public void setName(String name) {
	this.name = name;
}


public int getAlignmentLength() {
	return alignmentLength;
}


public void setAlignmentLength(int alignmentLength) {
	this.alignmentLength = alignmentLength;
}


public double getQuality() {
	return quality;
}


public void setQuality(double quality) {
	this.quality = quality;
}


public int getBegin_q() {
	return begin_q;
}



public void setBegin_q(int begin_q) {
	this.begin_q = begin_q;
}



public int getBegin_d() {
	return begin_d;
}



public void setBegin_d(int begin_d) {
	this.begin_d = begin_d;
}



public int getEnd_q() {
	return end_q;
}



public void setEnd_q(int end_q) {
	this.end_q = end_q;
}



public int getEnd_d() {
	return end_d;
}



public void setEnd_d(int end_d) {
	this.end_d = end_d;
}


@Override
public String toString() {
	return "PacBioBlastHitObject [begin_q=" + begin_q + ", begin_d=" + begin_d
			+ ", end_q=" + end_q + ", end_d=" + end_d + ", name=" + name
			+ ", alignmentLength=" + alignmentLength + ", quality=" + quality
			+ ", type=" + type + "]";
}



	
	
	
	
	
}
